home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / RTANKSRC.ZIP / LOADPCX.C < prev    next >
C/C++ Source or Header  |  1995-03-07  |  4KB  |  176 lines

  1. void mprintf(char *s);
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <alloc.h>
  6. #include <conio.h>
  7. #include <dos.h>
  8. #include <string.h>
  9.  
  10. #include "loadpcx.h"
  11.  
  12. #define NUMY_lb 10
  13. #define NUMY_hb 11
  14. #define NUMX_lb 66  /* In bytes, not pixels */
  15. #define NUMX_hb 67
  16.  
  17. #define REP_MASK 0xC0
  18. #define CNT_MASK 0x3f
  19.  
  20. #define MAKE_WORD(h,l) ((header[h] << 8) + header[l])
  21.  
  22. static int pcolor=3;
  23.  
  24.  /*<f>----------------------------------------
  25.   * FUNCTION: <s> void Load_CGA_PCX(char *fn)
  26.   * PURPOSE : Load in a CGA (ONLY!) .PCX file into screen buffer
  27.   *         :
  28.   * CREATION: 02/13/1989 13:32:39
  29.   */
  30. void Load_CGA_PCX(char *fn)
  31. {
  32. FILE *fp;
  33. unsigned char header[130];
  34. int nx,ny, size;
  35. int count, rep, data;
  36. unsigned char far *buf;
  37. unsigned char far *pbuf;
  38. unsigned char far *pbuf1;
  39. unsigned char far *scr;
  40. unsigned char far *scr1;
  41. int swap,b;
  42. int odd;
  43.  
  44.    randomize();
  45.  
  46.    buf=(unsigned char far *) farmalloc(25000L);
  47.    if (buf==0L) {
  48.       printf("Cannot alloc() memory for screen buffer\n");
  49.       exit(1);
  50.    }
  51.  
  52.    if ((fp=fopen(fn,"rb"))==NULL) {
  53.       printf("Cannot fopen \"%s\" for input\n",fn);
  54.       farfree(buf);
  55.       exit(1);
  56.    }
  57.  
  58.    pbuf=buf;
  59.  
  60.    fread(header,128,1,fp);
  61.  
  62.    nx=MAKE_WORD(NUMY_hb, NUMY_lb);
  63.    ny=MAKE_WORD(NUMX_hb, NUMX_lb);
  64.  
  65.    size=(ny+1)*nx;
  66.  
  67.    count=0; swap=0; odd=0;
  68.  
  69.    while (count<size) {
  70.  
  71.       rep=1;
  72.       b=getc(fp) & 255;
  73.  
  74.       if (REP_MASK == (REP_MASK & b)) {
  75.      rep = CNT_MASK & b;
  76.      b = getc(fp) & 255;
  77.       }
  78.       data = b;
  79.  
  80.       count += rep;
  81.       swap  += rep;
  82.       while (rep--)
  83.      *pbuf++ = data;
  84.       if (swap>=80) {
  85.      if (!odd)
  86.         pbuf+=(0x2000-80);
  87.      else
  88.         pbuf-=0x2000;
  89.      odd=~odd;
  90.      swap-=80;
  91.       }
  92.    }
  93.  
  94.    scr =(unsigned char far *) 0xB8000000L;
  95.    scr1=(unsigned char far *) 0xB8002000L;
  96.  
  97. /* ---- WIPE #1 Top to Bottom & bottom to top */
  98. /*
  99.    pbuf=buf;
  100.    pbuf1=buf+0x2000+8000;
  101.    scr1+=8000;
  102.  
  103.    for (b=0; b<8000; b++) {
  104.       *scr++ =*pbuf++;
  105.       *scr1--=*pbuf1--;
  106.       delay(1);
  107.    }
  108. */
  109. /*  -----  */
  110.  
  111.    for (b=0; b<8000; b++) {
  112.  
  113.       count=random(8000);
  114.       pbuf=buf+count;
  115.       pbuf1=buf+0x2000+count;
  116.  
  117.       scr =(unsigned char far *) 0xB8000000L+count;
  118.       scr1=(unsigned char far *) 0xB8002000L+count;
  119.  
  120.       *scr =*pbuf;
  121.       *scr1=*pbuf1;
  122.    }
  123.  
  124.    pbuf=buf;
  125.    pbuf1=buf+0x2000;
  126.    scr =(unsigned char far *) 0xB8000000L;
  127.    scr1=(unsigned char far *) 0xB8002000L;
  128.  
  129.    for (b=0; b<8000; b++) {
  130.       *scr++ =*pbuf++;
  131.       *scr1++=*pbuf1++;
  132.    }
  133. /*  -----  */
  134.  
  135.    fclose(fp);
  136.    farfree(buf);
  137. } /* void Load_CGA_PCX(char *fn) */
  138.  
  139. /*<f>----------------------------------------
  140.  * FUNCTION: <s> void set_screen_mode(int mode)
  141.  * PURPOSE : Set screen mode thru BIOS int 10h
  142.  *         :
  143.  * CREATION: 02/13/1989 13:34:46
  144.  */
  145. void set_screen_mode(int mode)
  146. {
  147. union REGS iregs, oregs;
  148.  
  149.    iregs.h.ah=0;
  150.    iregs.h.al=mode;
  151.    int86(0x10,&iregs,&oregs);
  152.  
  153. } /* void set_screen_mode(int mode) */
  154.  
  155. /*<f>----------------------------------------
  156.  * FUNCTION: <s> void mprintf(char *s)
  157.  * PURPOSE :
  158.  *         :
  159.  * CREATION: 02/14/1989 16:31:42
  160.  */
  161. void mprintf(char *s)
  162. {
  163. int a;
  164. union REGS ireg, oreg;
  165.  
  166.    for (a=0; a<strlen(s); a++) {
  167.       ireg.h.ah=0x0A;
  168.       ireg.h.al=(char) *(s+a);
  169.       ireg.h.bh=0;
  170.       ireg.h.bl=128+pcolor;
  171.       ireg.x.cx=1;
  172.       int86(0x10,&ireg,&oreg);
  173.       gotoxy(wherex()+1,wherey());
  174.    }
  175.  
  176. } /* void mprintf(char *s) */